package com.ansion.utils;

import android.content.SharedPreferences;
import android.text.TextUtils;

import com.ansion.bean.GroupInfo;
import com.ansion.constant.BConstant;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;


public class SettingHelper {
    private static final String TAG = "SettingHelper";


    public static void clearCurrentUser(long uid) {
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp == null)
            return;
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.commit();
    }

    private static SharedPreferences getCurrentUserSharedPreferences() {

//        CurrentUser user = LoginedUserMgr.getCurrentLoginedUser();
//        if (user == null || user.getUserId() < 0) {
//            return null;
//        }
        if (TextUtils.isEmpty(ContactUtil.getMyUid()) || ContactUtil.getMyUidLong() <= 0)
            return null;

        return ResourceUtils.getSharedPreferences("User_" + ContactUtil.getMyUid());
    }

    public static void saveSetting(String key, String value) {
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putString(key, value);
            editor.commit();
        }
    }

    public static void saveSetting(String key, int value) {
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putInt(key, value);
            editor.commit();
        }
    }

    public static void saveSetting(String key, long value) {
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putLong(key, value);
            editor.commit();
        }
    }

    public static void saveSetting(String key, boolean value) {
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean(key, value);
            editor.commit();
        }
    }

    public static void saveSetting(String key, float value) {
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            SharedPreferences.Editor editor = sp.edit();
            editor.putFloat(key, value);
            editor.commit();
        }
    }

    public static String getSetting(String key, String defValue) {

        String value = defValue;
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            value = sp.getString(key, defValue);
        }
        return value;
    }

    public static boolean getSetting(String key, boolean defValue) {
        boolean value = defValue;
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            value = sp.getBoolean(key, defValue);
        }
        return value;
    }

    public static long getSetting(String key, long defValue) {
        long value = defValue;
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            value = sp.getLong(key, defValue);
        }
        return value;
    }

    public static double getSetting(String key, float defValue) {
        float value = defValue;
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            value = sp.getFloat(key, defValue);
        }
        return value;
    }

    public static int getSetting(String key, int defValue) {
        int value = defValue;
        SharedPreferences sp = getCurrentUserSharedPreferences();
        if (sp != null) {
            value = sp.getInt(key, defValue);
        }
        return value;
    }

    public static void setNotificationAlert(boolean enable_alert) {

        saveSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_ALERT_KEY, enable_alert);
    }

    public static void setNotificationPreview(boolean preview) {
        saveSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_PREVIEW_KEY, preview);
    }

//	public static void setAutoacceptfriend(boolean auto_permit) {
//		saveSetting(
//				SettingConstants.GeneralConfigSetting.PRIVACY_AUTOACCEPT_FRIENDS_KEY,
//				auto_permit);
//	}

    public static void setNotificationSound(String sound_key) {
        saveSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_SOUND_URI, sound_key);
    }

    public static void setNotificationVibrate(boolean enable_vibrate) {
        saveSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_VIBRATE_KEY,
                enable_vibrate);
    }

    public static boolean getNotificationVibrate() {
        return getSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_VIBRATE_KEY,
                SettingConstants.GeneralConfigSetting.NOTIFICATION_VIBRATE_DEFAULT);
    }

    public static void setNotificationFriendJoin(boolean enable) {
        saveSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_FRIEND_JOIN,
                enable);
    }

    public static boolean getNotificationFriendJoin() {
        return getSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_FRIEND_JOIN,
                SettingConstants.GeneralConfigSetting.NOTIFICATION_FRIEND_JOIN_DEFAULT);
    }

    private static Boolean chatSoundSwitch;

    public static void setChatSoundSwitch(boolean enable) {
        chatSoundSwitch = enable;
        saveSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_CHAT_SOUND, enable);
    }

    public static boolean getChatSoundSwitch() {
        if (chatSoundSwitch != null) {
            return chatSoundSwitch;
        }
        return chatSoundSwitch = getSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_CHAT_SOUND, true);
    }

    public static void setHaveShownFriendquanGuide(boolean haveShown) {
        saveSetting(SettingConstants.GeneralConfigSetting.HAVESHOWN_FRIENDQUAN_GUIDE, haveShown);
    }

    public static boolean getHaveShownFriendquanGuide() {
        return getSetting(SettingConstants.GeneralConfigSetting.HAVESHOWN_FRIENDQUAN_GUIDE, false);
    }
//	public static void setNotificationGroupnearby(boolean enable_groupnearby) {
//		saveSetting(GeneralConfigSetting.NOTIFICATION_GROUPNEARBY_NOTIFY,
//				enable_groupnearby);
//	}
//
//	public static void setNotificationSMS(boolean enableSMS) {
//		saveSetting(GeneralConfigSetting.NOTIFICATION_SMS, enableSMS);
//	}
//
//	public static void setNotificationCocoMessages(boolean enable) {
//		saveSetting(
//				SettingConstants.GeneralConfigSetting.NOTIFICATION_COCO_MESSAGES,
//				enable);

//	}
//    public static boolean getNotificationAlert() {
//
//        return getSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_ALERT_KEY,
//                SettingConstants.GeneralConfigSetting.NOTIFICATION_ALERT_DEFAULT);

//    }

    public static boolean getNotificationPreview() {
        return getSetting(SettingConstants.GeneralConfigSetting.NOTIFICATION_PREVIEW_KEY,
                SettingConstants.GeneralConfigSetting.NOTIFICATION_PREVIEW_DEFAULT);
    }


//	public static boolean getNotificationGroupnearby() {
//		return getSetting(GeneralConfigSetting.NOTIFICATION_GROUPNEARBY_NOTIFY,
//				GeneralConfigSetting.NOTIFICATION_GROUPNEARBY_NOTIFY_DEFAULT);
//	}
//
//	public static boolean getNotificationSMS() {
//		return getSetting(GeneralConfigSetting.NOTIFICATION_SMS,
//				GeneralConfigSetting.NOTIFICATION_SMS_DEFAULT);
//	}
//
//	public static boolean getNotificationCocoMessages() {
//		return getSetting(GeneralConfigSetting.NOTIFICATION_COCO_MESSAGES,
//				GeneralConfigSetting.NOTIFICATION_COCOMESSAGES_DEFAULT);
//	}
//
//	public static boolean getAutoacceptfriend() {
//		return getSetting(GeneralConfigSetting.PRIVACY_AUTOACCEPT_FRIENDS_KEY,
//				GeneralConfigSetting.PRIVACY_AUTOACCEPT_FRIENDS__DEFAULT);
//	}

    public static String getLastReminderUpdateVersion() {
        return SharedPref.getInstance().getString(
                SharedPrefConstants.PREFENCE_LAST_UPDATE_REMINDER_VERSION,
                ApplicationHelper.getStrLocalversion());

    }

//	public static void setLastReminderUpdateVersion(String version) {
//		BabaApplication.getSharedPref().putString(
//				SharedPrefConstants.PREFENCE_LAST_UPDATE_REMINDER_VERSION,
//				version);
//	}
//
//	public static boolean needReminderUpdate() {
//		CheckVersionBean checker = CheckVersionHelper.getInstance()
//				.getCheckVersionBean();
//		if (checker == null) {
//			return false;
//		}
//		return checker.needUpdate()
//				&& !getLastReminderUpdateVersion().equals(
//						checker.getLatestversion());
//	}

    public static int getMaintabIndex() {
        return getSetting(SettingConstants.SETTING_LAST_TAB_INDEX, 0);
    }

    public static void saveMaintabIndex(int pos) {
        saveSetting(SettingConstants.SETTING_LAST_TAB_INDEX, pos);
    }

//	public static boolean hasNewSticker() {
//		return getSetting(StickerSetting.HAS_NEW_STICKER, false);
//	}
//
//	public static void saveNewSticker(boolean flag) {
//		saveSetting(StickerSetting.HAS_NEW_STICKER, flag);
//	}
//
//	public static long getStickerTime() {
//		return getSetting(StickerSetting.MARKET_STICKER_TIME, 0);
//	}
//
//	public static void saveStickerTime(long time) {
//		saveSetting(StickerSetting.MARKET_STICKER_TIME, time);
//	}
//
//	public static long getCustomStickerTime() {
//		return getSetting(StickerSetting.CUSTOM_STICKER_TIME, 0);
//	}
//
//	public static void saveCustomStickerTime(long time) {
//		saveSetting(StickerSetting.CUSTOM_STICKER_TIME, time);
//	}
//
//	public static long getStickerUpdateTime() {
//		return getSetting(StickerSetting.STICKER_UPDATE_TIME, 0);
//	}
//
//	public static void saveStickerUpdateTime(long time) {
//		saveSetting(StickerSetting.STICKER_UPDATE_TIME, time);
//	}
//
//	public static void setNeedReminderSetPwd(boolean need) {
//		saveSetting(SettingConstants.RegisterConfigSetting.NEEDREMINDER_SETPWD,
//				need);
//	}

    public static boolean getNeedReminderSetPwd() {
        return getSetting(
                SettingConstants.RegisterConfigSetting.NEEDREMINDER_SETPWD,
                SettingConstants.RegisterConfigSetting.NEEDREMINDER_SETPWD_DEFAULT);
    }

//	/**
//	 *
//	 * @param count
//	 *            邀请好友数量统计
//	 */
//	public static void saveInvtiteContactfriendCount(int count) {
//		saveSetting(SettingConstants.INVITE_CONTACTFRIEND_COUNT, count);
//	}
//
//	/**
//	 *
//	 * 邀请好友数量统计
//	 */
//	public static int getInvtiteContactfriendCount() {
//		return getSetting(SettingConstants.INVITE_CONTACTFRIEND_COUNT, 0);
//	}

    //	/**
//	 *
//	 * @param time
//	 *            标识客户端本地上次更新好友列表的时间
//	 */
//	public static void saveFriendUpdateTime(long time) {
//		saveSetting(FriendSetting.FRIENDLIST_UPDATETIME, time);
//	}
//
//	/**
//	 *
//	 * 标识客户端本地上次更新好友列表的时间
//	 */
//	public static long getFriendUpdateTime() {
//		return getSetting(FriendSetting.FRIENDLIST_UPDATETIME, 0);
//	}
//
//	public static void saveAboutMeDraft(String draft) {
//		saveSetting(AboutMe.AboutMe, draft);
//	}
//
//	public static String getAboutMeDraft() {
//		return getSetting(AboutMe.AboutMe, "");
//	}
//
    public static boolean getCallsVibrate() {
        return getNotificationVibrate() && getSetting(SettingConstants.GeneralConfigSetting.CALLS_VIBRATE_KEY,
                SettingConstants.GeneralConfigSetting.CALLS_VIBRATE_DEFAULT);
    }

//	public static void setCallsVibrate(boolean isChecked) {
//		saveSetting(GeneralConfigSetting.CALLS_VIBRATE_KEY, isChecked);
//
//	}
//
//	public static boolean getCallsAcceptOnlyFriend() {
//		return getSetting(GeneralConfigSetting.CALLS_ACCEPT_ONLY_FRIEND_KEY,
//				GeneralConfigSetting.CALLS_ACCEPT_ONLY_FRIEND_DEFAULT);
//	}

    public static void setCallsAcceptOnlyFriend(boolean isChecked) {
        saveSetting(SettingConstants.GeneralConfigSetting.CALLS_ACCEPT_ONLY_FRIEND_KEY,
                isChecked);

    }


    public static void savePersonalPrivacy(String key, int lastSeenPrivacy) {
        saveSetting(key, lastSeenPrivacy);
    }

    public static void saveHaveReadPrivacyType(int haveReadPrivacyType) {
        saveSetting(SettingConstants.CurrentUserSetting.HAVE_READ_PRIVACY_TYPE,
                haveReadPrivacyType);
    }
    public static void saveVipBadgePrivacyType(int vipBadge) {
        saveSetting(SettingConstants.CurrentUserSetting.VIP_BADGE_PRIVACY_TYPE,
                vipBadge);
    }

    public static void saveCallWifiUse4gType(int useWifi4g) {
        saveSetting(BConstant.VoipConstans.HAVE_WIFI4G_TYPE,
                useWifi4g);
    }

    public static int getCallWifiUse4gType() {
        return getSetting(BConstant.VoipConstans.HAVE_WIFI4G_TYPE,
                SettingConstants.CurrentUserSetting.HAVE_WIFI4G_TYPE_DEFULT);
    }

    public static int getHaveReadPrivacyType() {

        return getSetting(SettingConstants.CurrentUserSetting.HAVE_READ_PRIVACY_TYPE,
                SettingConstants.CurrentUserSetting.HAVE_READ_PRIVACY_TYPE_DEFULT);

    }
    public static int getVipBadgePrivacyType() {
        return getSetting(SettingConstants.CurrentUserSetting.VIP_BADGE_PRIVACY_TYPE,
                SettingConstants.CurrentUserSetting.VIP_BADGE_PRIVACY_TYPE_DEFAULT);
    }

    /**
     * 开关默认关闭
     * @return
     */
    public static boolean getShowSecurityNotification() {
        return getSetting(SettingConstants.CurrentUserSetting.KEY_SHOW_SECURITY_NOTIFICATION, false);
    }

    public static void setShowSecurityNotification(boolean isShow) {
        saveSetting(SettingConstants.CurrentUserSetting.KEY_SHOW_SECURITY_NOTIFICATION, isShow);
    }

    public static boolean hasEnableReadPrivacy() {
        return getHaveReadPrivacyType() == 1;
    }

    public static boolean hasCallWifi4g() {
        return getCallWifiUse4gType() == 1;
    }

    /**
     * 客户端syncContacts，上传全新的通讯录(increment=false).这里表示increment
     * 默认是false，当发送过上传请求并且成功修改为true
     *
     * @return
     */
    public static boolean getUploadContactInCrement() {

        return getSetting(SettingConstants.FriendSetting.UPLOADCONTACT_INCREMENT,
                SettingConstants.FriendSetting.UPLOADCONTACT_INCREMENT_DEFAULT);

    }

    public static void setUploadContactInCrement(boolean inCrement) {

        saveSetting(SettingConstants.FriendSetting.UPLOADCONTACT_INCREMENT, inCrement);
    }

//	public static boolean isLoadedSystemSMSCallLog() {
//		return getSetting(LoginSyncDataSetting.SETTING_IS_LOAD_SMS_CALLLOG,
//				false);
//	}
//
//	public static void setLoadedSystemSMSCallLog(boolean loaded) {
//		saveSetting(LoginSyncDataSetting.SETTING_IS_LOAD_SMS_CALLLOG, loaded);
//	}

//	public static boolean getIsNewActivated() {
//		return getSetting(ActivateSetting.Is_NEW_ACTIVATED,
//				false);
//	}

    public static void setIsNewActivated(boolean isNewActivated) {
        saveSetting(SettingConstants.ActivateSetting.Is_NEW_ACTIVATED, isNewActivated);
    }

    public static void setEnableVoiceCall(boolean enable) {
        saveSetting(
                SettingConstants.GeneralConfigSetting.ENABLE_VOICE_CALL_KEY,
                enable);
    }

    public static boolean getEnableVoiceCall() {
        return getSetting(SettingConstants.GeneralConfigSetting.ENABLE_VOICE_CALL_KEY,
                SettingConstants.GeneralConfigSetting.ENABLE_VOICE_CALL_DEFAULT);
    }

    public static void setEnableVideoCall(boolean enable) {
        saveSetting(SettingConstants.GeneralConfigSetting.ENABLE_VIDEO_CALL_KEY, enable);
    }

    public static boolean getEnableVideoCall() {
        return getSetting(SettingConstants.GeneralConfigSetting.ENABLE_VIDEO_CALL_KEY,
                SettingConstants.GeneralConfigSetting.ENABLE_VIDEO_CALL_DEFAULT);
    }

    public static void savePhotoAutoDownloadOption(int autoDownloadOption) {
        saveSetting(SettingConstants.CurrentUserSetting.PHOTO_AUTO_DOWNLOAD,
                autoDownloadOption);
    }

    public static int getPhotoAutoDownloadOption() {

        return getSetting(SettingConstants.CurrentUserSetting.PHOTO_AUTO_DOWNLOAD,
                SettingConstants.AutoDownLoadOption.PHOTO_DEFULT);

    }

    public static void saveWebloginQRCodeTipShown(boolean shown) {
        saveSetting(SettingConstants.GeneralConfigSetting.WEBLOGIN_QRCODE_TIPSHOWN_KEY, shown);
    }

    public static boolean getWebloginQRCodeTipShown() {
        return getSetting(SettingConstants.GeneralConfigSetting.WEBLOGIN_QRCODE_TIPSHOWN_KEY, false);
    }

    public static void saveVideoAutoDownloadOption(int autoDownloadOption) {
        saveSetting(SettingConstants.CurrentUserSetting.VIDEO_AUTO_DOWNLOAD,
                autoDownloadOption);
    }

    public static int getVideoAutoDownloadOption() {

        return getSetting(SettingConstants.CurrentUserSetting.VIDEO_AUTO_DOWNLOAD,
                SettingConstants.AutoDownLoadOption.VIDEO_DEFULT);

    }

    public static int getOrginalPhotoAutoDownloadOption() {
        return getSetting(SettingConstants.CurrentUserSetting.ORGINALPHOTO_AUTO_DOWNLOAD,
                SettingConstants.AutoDownLoadOption.FULL_IMAGE_DEFAULT);
    }

    public static void saveOriginalPhtoAutoDownloadOption(int autoDownloadOption) {
        saveSetting(SettingConstants.CurrentUserSetting.ORGINALPHOTO_AUTO_DOWNLOAD, autoDownloadOption);
    }

    public static void saveAutoSaveGalleryOption(boolean enable) {
        saveSetting(SettingConstants.CurrentUserSetting.AUTO_SAVE, enable);
    }

    public static boolean getAutoSaveGalleryOption() {
        return getSetting(SettingConstants.CurrentUserSetting.AUTO_SAVE, SettingConstants.CurrentUserSetting.AUTO_SAVE_DEFAULT);
    }

//	public static void saveAutoSaveGalleryOption(boolean autoSaveGalleryOption) {
//        saveSetting(CurrentUserSetting.AUTO_SAVE_GALLERY, autoSaveGalleryOption);
//    }
//	public static boolean getAutoSaveGalleryOption(){
//        return getSetting(CurrentUserSetting.AUTO_SAVE_GALLERY,CurrentUserSetting.AUTO_SAVE_GALLERY_DEFAULT);
//    }

    /**
     * 纪录进入Maintab的次数，
     *
     * @return
     */
//	public static int getAppBringFrontCount() {
//
//		return getSetting(RegisterConfigSetting.ENTER_MAINTAB_COUNT, 0);
//	}

    /**
     * 每次重新激活清零
     *
     * @param count
     */
//	public static void setAppBringFrontCount(int count) {
//
//		saveSetting(RegisterConfigSetting.ENTER_MAINTAB_COUNT, count);
//	}

    public static int newMatchFriend = 0;

    public static void setNewMatchFriend(int count) {
        newMatchFriend = count;
    }

    public static void addNewMatchFriend(int count) {
        newMatchFriend += count;
    }

    public static int getNewMatchFriend() {
        return newMatchFriend;
    }

    public static boolean getMatchUserForActivateFinish() {

        return getSetting(SettingConstants.ActivateSetting.MATCHUSER_FORACTIVATEFINISH,
                SettingConstants.ActivateSetting.MATCHUSER_FORACTIVATEFINISH_DEFAULT);
    }

    public static void setMatchUserForActivateFinish(boolean finish) {

        saveSetting(SettingConstants.ActivateSetting.MATCHUSER_FORACTIVATEFINISH, finish);

    }

    public static long getLastLoginTime() {
        return getSetting(SettingConstants.LoginSyncDataSetting.LAST_CHECK_LOGIN_TIME, -1L);
    }

    public static void saveLastLoginTime(long millSeconds) {
        saveSetting(SettingConstants.LoginSyncDataSetting.LAST_CHECK_LOGIN_TIME, millSeconds);

    }

    public static void setContactFirstMatched(boolean isFirstMatched) {
        saveSetting(SettingConstants.ContactSetting.FIRT_MATCHED, isFirstMatched);
    }

    public static boolean isContactFirstMatched() {
        return getSetting(SettingConstants.ContactSetting.FIRT_MATCHED, SettingConstants.ContactSetting.FIRT_MATCHED_DEFAULT);
    }

    public static void setContactFirstUploaded(boolean isFirstUploaded) {
        saveSetting(SettingConstants.ContactSetting.FIRT_UPLOADED, isFirstUploaded);
    }

    public static boolean isContactFirstUploaded() {
        return getSetting(SettingConstants.ContactSetting.FIRT_UPLOADED, SettingConstants.ContactSetting.FIRT_UPLOADED_DEFAULT);
    }

    public static boolean isCheckedOldVersionUploadContact() {
        return getSetting(SettingConstants.ContactSetting.CHECKED_OLD_VERSION_UPLOAD, SettingConstants.ContactSetting.CHECKED_OLD_VERSION_UPLOAD_DEFAULT);
    }

    public static void setCheckedOldVersionUploadContact(boolean isChecked) {
        saveSetting(SettingConstants.ContactSetting.CHECKED_OLD_VERSION_UPLOAD, isChecked);
    }

    public static void saveFavouriteGroups(List<GroupInfo> favGroupList) {

        if (favGroupList == null) {
            return;
        }
        saveSetting(SettingConstants.GeneralConfigSetting.FAVOURITE_GROUPS_KEY, GsonUtil.toJson(favGroupList));

    }

    public static List<GroupInfo> getFavouriteGroups() {
        String value = getSetting(SettingConstants.GeneralConfigSetting.FAVOURITE_GROUPS_KEY, "");
        if (TextUtils.isEmpty(value)) {
            return null;
        }
        Type listType = new TypeToken<List<GroupInfo>>() {
        }.getType();

        List<GroupInfo> favGroupList = GsonUtil.fromJson(value, listType);
        return favGroupList;
    }

    public static boolean isInGroupFav(long gid) {
        List<GroupInfo> favGroupList = getFavouriteGroups();
        if (favGroupList == null || favGroupList.size() == 0) {
            return false;
        }
        for (GroupInfo groupInfo : favGroupList) {
            if (groupInfo == null) {
                continue;
            }
            if (groupInfo.getGid() == gid) {
                return true;
            }
        }
        return false;
    }


    public static void setBackgroundImage(String path) {
        saveSetting(SettingConstants.GeneralConfigSetting.BACKGROUND_IMAGE_KEY, path);
    }

    public static void setUserBackgroundTime(long userId, long time) {
        saveSetting(userId + "_" + ContactUtil.getType(userId) + SettingConstants.GeneralConfigSetting.SETTING_BACKGROUND_TIME, time);
    }

    public static long getUserBackgroundTime(long userId) {
        return getSetting(userId + "_" + ContactUtil.getType(userId) + SettingConstants.GeneralConfigSetting.SETTING_BACKGROUND_TIME, (long) -1);
    }

    public static void setSettingGlobalBackgroundTime(long time) {
        saveSetting(SettingConstants.GeneralConfigSetting.SETTING_GLOBLE_BACKGROUD_TIME, time);
    }

    public static long getSettingGlobalBackgroundTime() {
        return getSetting(SettingConstants.GeneralConfigSetting.SETTING_GLOBLE_BACKGROUD_TIME, (long) -1);
    }

    public static String getBackgroundImage() {
        return getSetting(SettingConstants.GeneralConfigSetting.BACKGROUND_IMAGE_KEY, "");
    }

    public static void setTellFriendShowCount(long count) {
        saveSetting(SettingConstants.TellFriendConstans.PREFENCE_SHOWTELLFRIEND_COUNT, count);
    }

    public static long getTellFriendShowCount() {
        return getSetting(SettingConstants.TellFriendConstans.PREFENCE_SHOWTELLFRIEND_COUNT, 0L);
    }

    public static void setTellFriendCount(long count) {
        saveSetting(SettingConstants.TellFriendConstans.PREFENCE_TELLFRIEND_COUNT, count);
    }

    public static long getTellFriendCount() {
        return getSetting(SettingConstants.TellFriendConstans.PREFENCE_TELLFRIEND_COUNT, 0L);
    }

    public static void setRecentCallLogGet(boolean isGeted) {
        saveSetting(SettingConstants.RecentCallLogGet.RECENTCALLLOGGET, isGeted);
    }

    public static boolean isRecentCallLogGet() {
        return getSetting(SettingConstants.RecentCallLogGet.RECENTCALLLOGGET, false);
    }

    public static void setNeedUploadOldNickName(boolean need) {

        saveSetting("NeedUploadOldNickName", need);
    }

    /**
     * alvin
     * fix BA-3788 Name中出现客户端有而服务端无的情况.新版本要统一把NickName上传到server.
     * 如果是从旧版本升级上来，这个值是不存在的，默认要上传。
     *
     * @return
     */
    public static boolean isNeedUploadOldNickName() {


        boolean defaultNeed = true;

        return getSetting("NeedUploadOldNickName", defaultNeed);
    }


    public static void setShowSomaNews(boolean showSomaNews) {
//		if (isShowSomaNews() != showSomaNews) {
//			saveSetting(SettingConstants.SomaNews.SHOWSOMANEWS, showSomaNews);
//			CocoLocalBroadcastUtil.sendLocalBroadcast(new Intent(ContactsFragment.ACTION_REFRESH_FAVOURATE));
//		}
    }


    public static void setContactFailUploadCount(int count) {
        saveSetting(SettingConstants.UploadContact.CONTACT_FAIL_UPLOAD_COUNT, count);
    }

    public static void setContactSuccessUploadCount(int count) {
        saveSetting(SettingConstants.UploadContact.CONTACT_SUCCESS_UPLOAD_COUNT, count);
    }

    public static void setContactStartUploadTime(long time) {
        saveSetting(SettingConstants.UploadContact.CONTACT_START_UPLOAD_TIME, time);
    }

    public static int getContactFailUploadCount() {
        return getSetting(SettingConstants.UploadContact.CONTACT_FAIL_UPLOAD_COUNT, 0);
    }

    public static int getContactSuccessUploadCount() {
        return getSetting(SettingConstants.UploadContact.CONTACT_SUCCESS_UPLOAD_COUNT, 0);
    }

    public static long getContactStartUploadTime() {
        return getSetting(SettingConstants.UploadContact.CONTACT_START_UPLOAD_TIME, ServerTime.getServerTimeMillisecond());
    }

    public static void setAbstractThreadLimitCountStartTime(String threadName, long time) {
        saveSetting(threadName + "_" + SettingConstants.AbstractTaskThreadLimitCountConstant.START_TIME, time);
    }

    public static long getAbstractThreadLimitCountStartTime(String threadName) {
        return getSetting(threadName + "_" + SettingConstants.AbstractTaskThreadLimitCountConstant.START_TIME, ServerTime.getServerTimeMillisecond());
    }

    public static void setAbstractThreadLimitCountLoopCount(String threadName, int count) {
        saveSetting(threadName + "_" + SettingConstants.AbstractTaskThreadLimitCountConstant.LOOP_COUNT, count);
    }

    public static int getAbstractThreadLimitCountLoopCount(String threadName) {
        return getSetting(threadName + "_" + SettingConstants.AbstractTaskThreadLimitCountConstant.LOOP_COUNT, 0);
    }

    public static void setSyncBlockListSuccess(boolean success) {
        saveSetting(SettingConstants.SyncBlockList.SYNC_BLOCK_LIST_STATE, success);
    }

    public static boolean getSyncBlockListSuccess() {
        return getSetting(SettingConstants.SyncBlockList.SYNC_BLOCK_LIST_STATE, false);
    }

    public static int getSubscribeRetryCount() {
        return getSetting(SettingConstants.PublicAccount.SUBSRIBEBATCH, 0);
    }

    public static void setSubscribeRetryCount(int count) {
        saveSetting(SettingConstants.PublicAccount.SUBSRIBEBATCH, count);
    }

    /**
     * oids 为空，就不弹
     *
     * @return
     */
    public static String getSubscribeBatchOids() {
        return getSetting(SettingConstants.PublicAccount.SUBSRIBEBATCH_OIDS, "");
    }

    public static void setSubscribeBatchOids(List<Long> oids) {

        StringBuffer buffer = new StringBuffer();
        if (oids != null && !oids.isEmpty()) {
            for (Long oid : oids) {
                buffer.append(oid);
                buffer.append(",");
            }
        }
        saveSetting(SettingConstants.PublicAccount.SUBSRIBEBATCH_OIDS, buffer.toString());
    }


    public static String getServerUploadFilePubKey() {
        return getSetting(SettingConstants.ServerUploadFile.PUBKEY, SettingConstants.ServerUploadFile.PUBKEY_DEFAULT);
    }

    public static void setServerUploadFilePubKey(String pubKey) {
        saveSetting(SettingConstants.ServerUploadFile.PUBKEY, pubKey);
    }

    public static void addAdsCheckCount(String key) {
        saveSetting(SettingConstants.AdsSetting.ADS_CHECKCOUNT + key, getAdsCheckCount(key) + 1);
    }

    public static int getAdsCheckCount(String key) {
        return getSetting(SettingConstants.AdsSetting.ADS_CHECKCOUNT + key, 0);
    }

    public static void setAdsCheckTime(String key) {
        saveSetting(SettingConstants.AdsSetting.ADS_CHECKTIME + key, ServerTime.getServerTimeMillisecond());
    }

    public static void setAdsShowTime(String key) {
        saveSetting(SettingConstants.AdsSetting.ADS_CHECKTIME + key, System.currentTimeMillis());
    }

    public static void clearAdsShowTime(String key) {
        saveSetting(SettingConstants.AdsSetting.ADS_CHECKTIME + key, 0l);
    }

    public static long getAdsShowTime(String key) {
        return getSetting(SettingConstants.AdsSetting.ADS_CHECKTIME + key, 0l);
    }

    public static long getAdsCheckTime(String key) {
        return getSetting(SettingConstants.AdsSetting.ADS_CHECKTIME + key, 0l);
    }

    public static void setAdsUnreadCount(int count) {
        saveSetting(SettingConstants.AdsSetting.ADS_UNREADCOUNT, count);
    }

    public static int getAdsUnreadCount() {
        return getSetting(SettingConstants.AdsSetting.ADS_UNREADCOUNT, 0);
    }

    public static String getLaunchAdsModel() {
        String ads = getSetting(SettingConstants.AdsSetting.ADS_LAUNCHADSMODEL, null);

        return ads;
    }

    public static void setLaunchAdsModel(String ads) {
        saveSetting(SettingConstants.AdsSetting.ADS_LAUNCHADSMODEL, ads);
    }

    public static boolean needReUploadContacts() {
        return getSetting(SettingConstants.UploadContact.CONTACT_NEEDREUPLOADCONTACTS, true);
    }

    public static void setNeedReUploadContacts(boolean needReUploadContacts) {
        saveSetting(SettingConstants.UploadContact.CONTACT_NEEDREUPLOADCONTACTS, needReUploadContacts);
    }

    public static void setReUploadContactsTime(long time) {
        saveSetting(SettingConstants.UploadContact.CONTACT_REUPLOADCONTACTS_TIME, time);
    }

    public static long getReUploadContactsTime() {
        return getSetting(SettingConstants.UploadContact.CONTACT_REUPLOADCONTACTS_TIME, 0l);
    }
}
